<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php 
	$ci = & get_instance();
	if(!isUserLogin()){
		redirect(site_url());exit();
	}
	$USER = $ci->user_entity->init('id', getUserId());
	$listPackages = $ci->coin_packages_entity->getCoinPackagesType('cod');
	
//	if($USER->getCodStatus() != 'verify'){
//		redirect(site_url("cricket/account/cod_verify"));
//	}
?>
<div id="center_content">
	<?php if($USER->getCountry() != 'India'):?>
		<div class="clrboth"></div>
		<div class="block">
			<div class="title" style="position:relative;">
				<h3 class="bold"><a href="<?php echo site_url("cricket/user/dashboard")?>">Dashboard</a> &raquo; Add CX coins</h3>
				<a class="back_button2" href="<?php echo site_url("cricket/user/dashboard")?>" title="Back?">Back?</a>	
			</div>
			<div class="clrboth"></div>
			<div class="content">
				<div class="rowitem3">
					<div class="clrboth"></div>
						<?php $this->load->view('cricket/user/payment_modes'); ?>
					<div class="clrboth"></div>	
					<br/>
					COD option is only for Indian users 
					
				</div>	
			</div>
		</div>	
		<div class="clrboth"></div>
		
	<?php else:?>

	<div class="clrboth"></div>
	<div class="block">
		<div class="title" style="position:relative;">
			<h3 class="bold"><a href="<?php echo site_url("cricket/user/dashboard")?>">Dashboard</a> &raquo; Add Coins</h3>
			<a class="back_button2" href="<?php echo site_url("cricket/user/dashboard")?>" title="Back?">Back?</a>	
		</div>
		<div class="clrboth"></div>
		<div class="content">
			<div class="rowitem3">
				<div class="clrboth"></div>
					<?php $this->load->view('cricket/user/payment_modes'); ?>
				<div class="clrboth"></div>	
				<br/>
				1. Choose a Package
				<div class="clrboth"></div>	
				
				<table class="summary">
					<thead>
						<td width="10%">Select</td>
						<td width="40%">Package</td>
						<td width="25%">Amount (INR)</td>
						<td width="25%">Coin</td>
					</thead>
					<tbody>
						<?php foreach($listPackages as $item): ?>
							<?php $PACKAGE = $ci->coin_packages_entity->init('id', $item->id); ?>
							<tr>
								<td><input type="radio" name="package" value="<?php echo $PACKAGE->getId();?>" style="cursor:pointer;" /></td>
								<td><?php echo $PACKAGE->getPackage();?></td>
								<td style="text-align:right;"><?php echo format_Money($PACKAGE->getCost(),true);?>&nbsp;</td>
								<td style="text-align:right;"><?php echo $PACKAGE->getCoin();?>&nbsp;</td>
							</tr>
						<?php endforeach;?>
					</tbody>
				</table>
				<div class="clrboth"></div>
				<br/>
				<div class="grid6" style="margin-bottom:50px;"><input type="button" class="submitclass" id="submit_button" /> <?php echo loader_image('id="loader_image" class="hidden"');?></div>
				<div class="clrboth"></div>
				<div class="grid6 red" id="system_error"></div>
				<div class="clrboth"></div>	
			</div>	
		</div>
	</div>	
	<div class="clrboth"></div>
</div>

<script type="text/javascript">
	google.setOnLoadCallback(function() {
		$('#cod_payment').addClass('current');
		
		$('#submit_button').bind('click',function(){
			$pack= $('input[name=package]:checked').val();
			if(!isNaturalNumber($pack)){
				alert("Please select a package firstly.");
				return false;
			}
			$('#loader_image').removeClass('hidden');
			
			jQuery.post(BASE_URI+'cricket/account/add_cod_submit',{ pid:$pack },function(res){
				if(res== 'ok'){
					queryURL(BASE_URI+MODULE+'/account/add_coins2_notify');
				}else if(res == 'need_verify'){
					queryURL(BASE_URI+MODULE+'/account/cod_verify');
				}else{
					alert(res);
					$('#loader_image').addClass('hidden');
				}
			}); 
		});
	});
	<?php if(isset($_SESSION['package_id']) AND $_SESSION['package_id'] != 0):?>	
		jQuery.post(BASE_URI+'cricket/account/add_cod_submit',{ pid:<?php echo $_SESSION['package_id'];?> },function(res){
			if(res== 'ok'){
				queryURL(BASE_URI+MODULE+'/account/add_coins2_notify');
			}else if(res == 'need_verify'){
				queryURL(BASE_URI+MODULE+'/account/cod_verify');
			}else{
				alert(res);
				$('#loader_image').addClass('hidden');
			}
		}); 
		
	<?php endif;?>	

</script>

<?php endif;?>

